package org.runecore.rs2.net;

import org.runecore.rs2.model.player.GameSession;
import org.runecore.rs2.model.player.Player;

/**
 * RuneCore
 * Sep 5, 2011
 * @author Harry Andreas<Harry@RuneCore.org>
 */

public class PacketBuilder {
	
	/**
	 * Send's the player's map region
	 * @param session
	 * @return
	 */
	public static void sendMapRegion(GameSession session) {
		Player player = session.getPlayer();
		player.setCurrentRegion(player.getLocation());
		StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(5);
		out.writeHeader(session.getEncryptor(), 73);
		out.writeShort(player.getLocation().getRegionX() + 6, StreamBuffer.ValueType.A);
		out.writeShort(player.getLocation().getRegionY() + 6);
		session.sendPacket(out.getBuffer());
	}
	
	/**
	 * Sends the tab's for login
	 * @param session
	 */
	public static void sendTabs(GameSession session) {
		int[] sidebars = {2423, 3917, 638, 3213, 1644, 5608, 1151, -1, 5065, 5715, 2449, 904, 147, 962};
		for (int i = 0; i < sidebars.length; i ++) {
			sendSidebarInterface(session, i, sidebars[i]);
		}
	}
	
	/**
	 * Sends sidebar interfaces
	 * @param session
	 * @param menuId
	 * @param form
	 */
	public static void sendSidebarInterface(GameSession session, int menuId, int form) {
		StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(4);
		out.writeHeader(session.getEncryptor(), 71);
		out.writeShort(form);
		out.writeByte(menuId, StreamBuffer.ValueType.A);
		session.sendPacket(out.getBuffer());
	}
	
	/**
	 * Sends Skills
	 * @param id
	 * @param value
	 * @param xp
	 */
	public static void sendSkill(GameSession session, int id, int value, int xp) {
		StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(8);
		out.writeHeader(session.getEncryptor(), 134);
		out.writeByte(id);
		out.writeInt(xp, StreamBuffer.ByteOrder.MIDDLE);
		out.writeByte(value);
		session.sendPacket(out.getBuffer());
	}

}